`
https://leetcode.cn/problems/decode-string
`

/**
 * @param {string} s
 * @return {string}
 */
var decodeString = function (s) {
  const stack = [];
  let res = '';
  let num = 0;
  for (const c of s) {
    if (!isNaN(c)) {
      num = num * 10 + parseInt(c);
    } else if (c === '[') {
      stack.push([res, num]);
      res = '';
      num = 0;
    } else if (c === ']') {
      const [prevStr, n] = stack.pop();
      res = prevStr + res.repeat(n);
    } else {
      res += c;
    }
  }
  return res;
};